package com.power.core
{
	import com.power.enum.ConfigUrl;
	import com.power.model.FloorVo;
	import com.power.model.RoomVo;
	import com.power.model.factories.CatetorysFactory;
	import com.power.model.factories.FloorFactory;
	import com.power.model.factories.RoomFactory;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class GetData extends EventDispatcher
	{
		private static var instance:GetData;
		
		private var roomFactory:RoomFactory;
		
		private var floorFactory:FloorFactory;
		
		private var categoryFactory:CatetorysFactory;
		
		private var roomTagFactory:RoomFactory;
		
		private var floorTagFactory:FloorFactory;
		
		public function GetData()
		{
			//this class is builded for getting all of data about room,floor,roombutton,floorbuttoon
			roomFactory = new RoomFactory();
			floorFactory = new FloorFactory();
			categoryFactory = new CatetorysFactory();
			roomTagFactory = new RoomFactory();
			floorTagFactory = new FloorFactory();
			
			startLoadAllData();
			setAllEventListener();
		
				
		}
		public static function GetInstance():GetData
		{
			if(instance == null) instance = new GetData();
			return instance;
		}
		private function startLoadAllData():void
		{
			roomFactory.addEventListener("ParserRoomDataEnd",parserRoomDataEndHandler);
			floorFactory.addEventListener("ParserFloorDataEnd",parserFloorDataEndHandler);
			categoryFactory.addEventListener("ParserCateGeroyEnd",parserCategroyEndHandler);
			
		}
		private function setAllEventListener():void
		{
			categoryFactory.startLoadedXml(ConfigUrl.CATETORY_URL);
		}
		private function parserRoomDataEndHandler(e:Event):void
		{
			floorFactory.startLoadFloorAssets(ConfigUrl.FLOOL_URL,"全部地板");
		}
		private function parserFloorDataEndHandler(e:Event):void
		{
			this.dispatchEvent(new Event("AllDataIsReadly"));
		}
		private function parserCategroyEndHandler(e:Event):void
		{
			roomFactory.startLoadRoomAssets(ConfigUrl.ROOM_URL,"全部房间");
		}
	
		public function getRoomData():Vector.<RoomVo>
		{
			return roomFactory.getRoomData();
		}
		public function getFloorData():Vector.<FloorVo>
		{
			return floorFactory.getFloorData();
		}
		public function getRoomCategorys():Array
		{
			return categoryFactory.getRoomCateGorys();
		}
		public function getFloorCategorys():Array
		{
			return categoryFactory.getFloorCateGorys();
		}
			
		
	}
}